package com.navinfo.platform.dataanalysis.dto;

import lombok.Data;

import java.io.Serializable;
import java.sql.Timestamp;
import org.apache.spark.sql.Column;
import org.apache.spark.sql.Row;

import static org.apache.spark.sql.functions.col;

@Data
public class AlarmInfoDto implements Serializable {
    private long uid;
    private long tid;

    private int so90Times;
    private int so90Duration;
    private int so90Mileage;
    private int so90100kmTimes;
    private int so90DurationProportion;
    private int so90MileageProportion;

    private int so120Times;
    private int so120Duration;
    private int so120Mileage;
    private int so120100kmTimes;
    private int so120DurationProportion;
    private int so120MileageProportion;

    private int srTimes;
    private int srDuration;
    private int srMileage;
    private int sr100kmTimes;
    private int srDurationProportion;
    private int srMileageProportion;

    private int lrogTimes;
    private int lrogDuration;
    private int lrogMileage;
    private int lrog100kmTimes;
    private int lrogDurationProportion;
    private int lrogMileageProportion;

    private int mileage;
    private int duration;
    private Timestamp updateTime;
    private String day;

    public static AlarmInfoDto parseRow(Row row){
        AlarmInfoDto alarmInfoDto = new AlarmInfoDto();
        alarmInfoDto.setUid(row.getAs("uid"));
        alarmInfoDto.setTid(row.getAs("tid"));

        alarmInfoDto.setSo90Times(row.getAs("so_90_times"));
        alarmInfoDto.setSo90Mileage(row.getAs("so_90_mileage"));
        alarmInfoDto.setSo90Duration(row.getAs("so_90_duration"));

        alarmInfoDto.setSo120Times(row.getAs("so_120_times"));
        alarmInfoDto.setSo120Mileage(row.getAs("so_120_mileage"));
        alarmInfoDto.setSo120Duration(row.getAs("so_120_duration"));

        alarmInfoDto.setSrTimes(row.getAs("sr_times"));
        alarmInfoDto.setSrMileage(row.getAs("sr_duration"));
        alarmInfoDto.setSrDuration(row.getAs("sr_mileage"));

        alarmInfoDto.setLrogTimes(row.getAs("lrog_times"));
        alarmInfoDto.setLrogMileage(row.getAs("lrog_mileage"));
        alarmInfoDto.setLrogDuration(row.getAs("lrog_duration"));

        alarmInfoDto.setMileage(row.getAs("mileage"));
        alarmInfoDto.setDuration(row.getAs("duration"));
        //alarmInfoDto.setDay(row.getAs("day"));

        return alarmInfoDto;
    }

    public static Column[] columns(){
        Column uid = col("uid").as("uid");
        Column tid = col("tid").as("tid");

        Column so90Times =	col("so90Times").as("so_90_times");
        Column so90Duration =	col("so90Duration").as("so_90_duration");
        Column so90Mileage =	col("so90Mileage").as("so_90_mileage");
        Column so90100kmTimes =	col("so90100kmTimes").as("so_90_100km_times");
        Column so90DurationProportion =	col("so90DurationProportion").as("so_90_duration_proportion");
        Column so90MileageProportion =	col("so90MileageProportion").as("so_90_mileage_proportion");

        Column so120Times =	col("so120Times").as("so_120_times");
        Column so120Duration =	col("so120Duration").as("so_120_duration");
        Column so120Mileage =	col("so120Mileage").as("so_120_mileage");
        Column so120100kmTimes =	col("so120100kmTimes").as("so_120_100km_times");
        Column so120DurationProportion =	col("so120DurationProportion").as("so_120_duration_proportion");
        Column so120MileageProportion =	col("so120MileageProportion").as("so_120_mileage_proportion");

        Column srTimes =	col("srTimes").as("sr_times");
        Column srDuration =	col("srDuration").as("sr_duration");
        Column srMileage =	col("srMileage").as("sr_mileage");
        Column sr100kmTimes =	col("sr100kmTimes").as("sr_100km_times");
        Column srDurationProportion =	col("srDurationProportion").as("sr_duration_proportion");
        Column srMileageProportion =	col("srMileageProportion").as("sr_mileage_proportion");

        Column lrogTimes =	col("lrogTimes").as("lrog_times");
        Column lrogDuration =	col("lrogDuration").as("lrog_duration");
        Column lrogMileage =	col("lrogMileage").as("lrog_mileage");
        Column lrog100kmTimes =	col("lrog100kmTimes").as("lrog_100km_times");
        Column lrogDurationProportion =	col("lrogDurationProportion").as("lrog_duration_proportion");
        Column lrogMileageProportion =	col("lrogMileageProportion").as("lrog_mileage_proportion");

        Column mileage = col("mileage").as("mileage");
        Column duration = col("duration").as("duration");
        Column updateTime = col("updateTime").as("update_time");
        Column day = col("day").as("day");

        return new Column[]{uid,tid,so90Times,so90Duration,so90Mileage,so90100kmTimes,so90DurationProportion,so90MileageProportion,so120Times,
                so120Duration,so120Mileage,so120100kmTimes,so120DurationProportion,so120MileageProportion,srTimes,srDuration,srMileage,sr100kmTimes,
                srDurationProportion,srMileageProportion,lrogTimes,lrogDuration,lrogMileage,lrog100kmTimes,lrogDurationProportion,lrogMileageProportion,
                mileage, duration, updateTime, day};
    }
}
